package com.leetroll.common.validator.constraints;

import com.leetroll.common.validator.annotation.IdValid;
import com.leetroll.common.constant.CharConstant;
import com.leetroll.common.utils.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * ID校验器，主要判断是否为空，并且长度是否为32
 */
public class IdValidator implements ConstraintValidator<IdValid, String> {


    @Override
    public void initialize(IdValid constraintAnnotation) {

    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return value != null && !StringUtils.isBlank(value) && !StringUtils.isEmpty(value.trim()) && value.length() == CharConstant.THIRTY_TWO;
    }
}
